<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <title>台风列表</title>
    <style type="text/css">
        a:link, a:visited {
            text-decoration: none; /*超链接无下划线*/
        }

        a:hover {
            text-decoration: underline; /*鼠标放上去有下划线*/
        }
    </style>
    <style type=text/css>
        body {
            background-image: url(background.png);
            background-repeat: no-repeat;
            background-position: center top;
        }
    </style>
</head>
<body>
<?php
/**
 * 以列表形式展示符合某个时间要求的台风
 * 通过GET方式得到时间段
 *
 * @author 周利发    zhoulifa@126.com
 */

// ------判断是否有GET------
$date = $_GET ["date"];
if ($date == 0) {
    echo 'no date';
    exit ();
}

// ------基本设定------
$config = parse_ini_file("config/db_config.ini");
$server = $config["server"];
$username = $config["username"];
$password = $config["password"];
$database = $config["database"];
$baseurl = "forecast.php";

$query = "select * from typhoon_total where date like '" . $date . "%';";
$conn = mysqli_connect($server, $username, $password, $database);
$result = mysqli_query($conn, $query);
// echo $query;

if (mysqli_num_rows($result) == 0) {
    echo '<table align="center">';
    echo '<tr><td align="center"><img src="/noty.png">< /img><td></tr>';
    echo '</table>';
    exit ();
}

mysqli_data_seek($result, 0);
$count_ty = 0;

// ------使用说明------
echo '<table bgcolor="#828282" border="1" cellspacing="0px" cellpadding="2px" align="center">';
echo '<tr><td width="100%" align="center">★★ 操作说明 ★★</td></tr>';
echo '<tr><td width="100%"><ol><br />';
echo '<li>点击单选框，选择台风，以此确定预测台风;';
echo '<li>在文本框输入数字，以此确定从第几个点开始进行预测;';
echo '<li>点击OK按钮，开始进行预测;';
echo '<li>另外，点击表格的台风名称链接时，能直接对该台风的第三个点进行预测;';
echo '</ol></td></tr>';

// ------用表单GET发送数据给预测页面------
echo '<tr><td>';
echo '<form action="' . $baseurl . '" method="get">';
echo '<p><table bgcolor="#828282" border="1" cellspacing="0px" cellpadding="2px" align="center">';
echo '<tr><td align = "center"></td>';
echo '<td align = "center">气旋编号</td>';
echo '<td align = "center">英文名称</td>';
echo '<td align = "center">中文名称</td></tr>';
while ($num_result = mysqli_fetch_row($result)) {
    // ------输出表的记录------
    // for($i = 0; $i < mysql_num_fields ( $result ); $i ++) {
    // echo $num_result [$i] . ' ';
    // }
    // echo '<br>';
    $count_ty++;

    $query_count = "SELECT num,name,level,date,count FROM typhoon_total WHERE num = '" . $num_result [0] . "'";
    $result_count = mysqli_query($conn, $query_count);
    $fetch_count = mysqli_fetch_row($result_count);

    $baseurl_get = 'http://1.bjxytyphoon.sinaapp.com/show.php?table=typhoon_detail&num=' . $num_result [0] . '&count=' . $fetch_count [4];
    echo '<tr>';
    echo '<td align = "center"><input type="radio" name="num" checked="checked" value="' . $num_result [0] . '">' . '</td>';
    echo '<td align = "center">' . $num_result [0] . '</td>';
    if (strpos($num_result [2], "nameless")) {
        $name_typhoon = '——';
    } else {
        $name_typhoon = $num_result [2];
    }

    echo '<td align = "center"><a href="' . $baseurl_get . '">' . $name_typhoon . '</a></td>';

    // ------查找中文名字------
    $query_name = "SELECT name_Chinese FROM typhoon_name WHERE name_English like '" . $name_typhoon . "'";
    // echo $query_name . '<br />';
    mysqli_query($conn, "set names UTF－8;");
    $result_name = mysqli_query($conn, $query_name);
    // ------判断是否数据库是否有数据返回------
    if (mysqli_fetch_row($result_name) == 0) {
        $name_Chinese = '——';
    } else {
        mysqli_data_seek($result_name, 0);
        while ($num_result = mysqli_fetch_row($result_name)) {
            // ------输出表的记录------
            for ($i = 0; $i < mysqli_num_fields($result_name); $i++) {
                // echo $num_result [$i] . ' ';
                $name_Chinese = $num_result [$i];
            }
        }
    }

    echo '<td align ="center"><a href=' . $baseurl_get . '>' . $name_Chinese . '</a></td>';
    echo '</tr>';
}
echo '</table><p>&nbsp&nbsp&nbsp&nbsp';
echo '<table border="0" cellspacing="0px" cellpadding="2px" align="center">';
echo '<tr align="center">请选择从台风第几个点进行预测（提示：点击上述台风名称可查看该台风的路径展示）</tr>';
echo '<tr>';
echo '<td align="center"><input id="pre" type="hidden" name="pre" value="list"></td>';
echo '<td align = "center"><input id="beg" type="text" name="beg" value="3"/>&nbsp;</tb>';
echo '<td align = "center"><input type="submit" value="确定" /></td>';
echo '</tr></table>';
echo '</form>';
echo '</td></tr></talbe>';
?>
</body>
</html>